package gcollection;

import com.google.common.collect.MoreCollectors;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.Optional;
import java.util.stream.Stream;


/**
 * 只生成一个元素
 */
public class collection {



    @Test
    private void t1() {

        var res = Stream.of("a", "b")
                .filter(str -> str.equals("a"))
                .collect(MoreCollectors.toOptional());

        Assert.assertEquals(Optional.of("a"), res);
        System.out.println(res);

    }

    @Test
    private void t2() {

        // 会直接报错
        var res2 = Stream.of("a", "b")
                .collect(MoreCollectors.toOptional());


    }

}
